<?php
namespace app\friend\loglic;

class Install
{
    //安装MYSQL版回调
    public function mysql()
    {
        //安装应用
        \daicuo\Apply::install('friend','install');
        
        //首页路由
        model('common/Route','loglic')->unInstall('friend');
        
        //设置首页
        model('common/Route','loglic')->index('friend/index/index', 'friend');
        
        return true;
    }
    
    //批量添加初始配置
    public function config()
    {
        config('common.validate_name', false);
        
        return \daicuo\Op::write([
            'theme'                => 'default',
            'theme_wap'            => 'default',
            'index_title'          => '友情链接',
            'index_keywords'       => '友情链接列表,友情链接插件',
            'index_description'    => '欢迎使用呆错友情链接插件，支持免费自助申请！',
            'publish_title'        => '免费申请',
            'publish_keywords'     => '友情链接,自助友情链接,友情链接插件',
            'publish_description'  => '免费申请友情链接前请先做好本站的链接！',
        ],'friend','config','system',0,'yes');
    }
    
    //批量定义语言包
    public function lang()
    {
        return true;
    }
    
    //批量写入插件动态字段
    public function field()
    {
        config('common.validate_name', false);
        
        //内容模型
        model('common/Field','loglic')->install(model('friend/Field','loglic')->detail());
        
        //发布字段
        model('common/Field','loglic')->install(model('friend/Field','loglic')->publishIndex());
        
        return true;
    }
    
    //批量添加路由伪静态
    public function route()
    {
        config('common.validate_name', false);
        
        model('common/Route','loglic')->install([
            [
                'rule'        => 'friend$',
                'address'     => 'friend/index/index',
                'method'      => 'get',
                'op_module'   => 'friend',
                'op_controll' => 'route',
                'op_action'   => 'system',
            ],
        ]);
        
        return true;
    }
    
    //批量添加用户
    public function user()
    {
        return true;
    }
    
    //批量添加角色（用户组）
    public function role()
    {
        return true;
    }
    
    //批量添加权限
    public function auth()
    {
        return true;
    }
    
    //批量添加后台菜单
    public function menu()
    {
        config('common.validate_name', false);
        
        model('common/Menu','loglic')->install([
            [
                'term_name'   => '友链',
                'term_slug'   => 'friend',
                'term_info'   => 'fa-handshake-o',
                'term_module' => 'friend',
            ],
        ]);
        
        model('common/Menu','loglic')->install([
            [
                'term_name'   => '友链管理',
                'term_slug'   => 'friend/admin/index',
                'term_info'   => 'fa-link',
                'term_module' => 'friend',
                'term_order'  => 7,
            ],
            [
                'term_name'   => '菜单管理',
                'term_slug'   => 'admin/navs/index?parent=friend&navs_module=friend&navs_action=index',
                'term_info'   => 'fa-sitemap',
                'term_module' => 'friend',
                'term_order'  => 6,
            ],
            [
                'term_name'   => '内容表单',
                'term_slug'   => 'admin/field/index?parent=friend&op_module=friend&op_controll=detail',
                'term_info'   => 'fa-file',
                'term_module' => 'friend',
                'term_order'  => 5,
            ],
            [
                'term_name'   => '发布表单',
                'term_slug'   => 'admin/field/index?parent=friend&op_module=friend&op_controll=publish',
                'term_info'   => 'fa-file-o',
                'term_module' => 'friend',
                'term_order'  => 4,
            ],
            [
                'term_name'   => '后台菜单',
                'term_slug'   => 'admin/menu/index?parent=friend&term_module=friend',
                'term_info'   => 'fa-navicon',
                'term_module' => 'friend',
                'term_order'  => 3,
            ],
            [
                'term_name'   => '语言定义',
                'term_slug'   => 'admin/lang/index?parent=friend&op_module=friend',
                'term_info'   => 'fa-commenting',
                'term_module' => 'friend',
                'term_order'  => 2,
            ],
            [
                'term_name'   => '频道设置',
                'term_slug'   => 'friend/config/index',
                'term_info'   => 'fa-gear',
                'term_module' => 'friend',
                'term_order'  => 1,
            ],
        ],'友链');
        
        return true;
    }
    
    //批量添加前台菜单
    public function navs()
    {
        config('common.validate_name', false);
        
        model('common/Navs','loglic')->install([
            [
                'navs_name'       => '友情链接',
                'navs_url'        => 'friend/index/index',
                'navs_type'       => 'navbar',
                'navs_module'     => 'friend',
                'navs_action'     => 'index',
                'navs_active'     => 'friendindexindex',
                'navs_target'     => '_self',
                'navs_order'      => 1,
            ],
            [
                'navs_name'       => '申请友链',
                'navs_url'        => 'friend/publish/index',
                'navs_type'       => 'bottom',
                'navs_module'     => 'friend',
                'navs_action'     => 'index',
                'navs_active'     => 'friendpublishindex',
                'navs_target'     => '_self',
                'navs_order'      => 1,
            ],
        ]);
        
        return true;
    }
    
    //批量添加初始分类
    public function category()
    {
        return true;
    }
    
    //批量添加初始标签
    public function tag()
    {
        return true;
    }
    
    //批量添加内容数据
    public function info()
    {
        config('common.validate_name', false);
        
        config('common.validate_scene', false);
        
        config('common.where_slug_unique', false);
        
        config('custom_fields.info_meta', ['friend_referer','logo_referer']);

        $list = [
            [
                'info_name'      => '呆错开发框架',
                'friend_referer' => 'https://www.daicuo.org',
                'info_order'     => 99,
                'info_module'    => 'friend',
                'info_controll'  => 'detail',
                'info_action'    => 'index',
                'info_staus'     => 'normal',
            ],
            [
                'info_name'      => '飞飞影视系统',
                'friend_referer' => 'https://www.feifeicms.org',
                'info_order'     => 98,
                'info_module'    => 'friend',
                'info_controll'  => 'detail',
                'info_action'    => 'index',
                'info_staus'     => 'normal',
            ],
            [
                'info_name'      => '呆错站长论坛',
                'friend_referer' => 'http://daicuo.co',
                'info_order'     => 97,
                'info_module'    => 'friend',
                'info_controll'  => 'detail',
                'info_action'    => 'index',
                'info_staus'     => 'normal',
            ],
        ];
        
        foreach($list as $key=>$post){
            \daicuo\Info::save($post, 'info_meta');
        }
        
        return true;
    }
}